package com.salmon.scommerce.config;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.datasource.AbstractDriverBasedDataSource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

@Configuration
@PropertySource("classpath:/com/salmon/properties/mysql.properties")
public class DataSourceConfig {
	
	private Logger LOG = LoggerFactory.getLogger(this.getClass()); 
	
	@Value("${mysql.driver}") String driver;
	@Value("${mysql.url}") String url;
	@Value("${mysql.username}") String username;
	@Value("${mysql.password}") String password;
	
	@Bean
	public DriverManagerDataSource getDataSource() {
		
		LOG.debug("driver is :" + driver);
		
		DriverManagerDataSource dataSource = new DriverManagerDataSource();
		dataSource.setDriverClassName(driver);
		dataSource.setUrl(url);
		dataSource.setUsername(username);
		dataSource.setPassword(password);
		
		return dataSource;
	}
}
